import request from '@/utils/request.js'

// 文章获取
export const getAllArticleListlsAPI = ({ channel_id, timestamp }) =>
    request({
        url: '/v1_0/articles',
        method: 'GET',
        params: {
            // 这里的参数axios会帮你拼接在URL后面
            channel_id,
            timestamp
        }
    })

// 文章-反馈-不感兴趣
export const dislikeArticleAPI = ({ artId }) =>
    request({
        url: '/v1_0/article/dislikes',
        method: 'POST',
        data: {
            target: artId
        }
    })

// 文章-反馈-反馈垃圾内容
export const reportArticleAPI = ({ artId, type }) =>
    request({
        url: '/v1_0/article/reports',
        method: 'POST',
        data: {
            target: artId,
            type: type,
            remark: '如果你想写,你可以逻辑页面判断下,如果点击类型是0,再给个弹出输入框输入其他问题，传参到这里'
        }
    })

// 文章-获取详情
export const detailAPI = ({ artId }) =>
    request({
        url: `/v1_0/articles/${artId}`
    })

// 文章-点赞
export const likeArticleAPI = (artId) =>
    request({
        url: 'v1_0/article/likings',
        method: 'POST',
        data: {
            target: artId
        }
    })

// 文章-取消点赞
export const unLikeArticleAPI = (artId) =>
    request({
        url: `v1_0/article/likings/${artId}`,
        method: 'DELETE'
    })

// 文章-评论列表
export const commentsListAPI = ({ id, offset = null, limit = 10 }) =>
    request({
        url: 'v1_0/comments',
        method: 'GET',
        params: {
            // axios只针对params参数，如果发现键值对，值为null,会忽略此参数名和值不携带在url？后面
            type: 'a', // 什么时候需要外面传：此值会变化
            source: id,
            offset,
            limit
        }
    })

// 文章-评论-喜欢
export const commentsLikingAPI = ({ comId }) => {
    return request({
        url: '/v1_0/comment/likings',
        method: 'POST',
        data: {
            target: comId
        }
    })
}

// 文章-评论-取消喜欢
export const commentsIDisLikingAPI = ({ comId }) => {
    return request({
        urlL: `/v1_0/comment/likings/${comId}`,
        method: 'DELETE'
    })
}

// 文章-评论-发布评论
export const commentSendAPI = ({ id, content, art_id = null }) => {
    const obj = {
        target: id,
        content
    }
    if (art_id !== null) {
        // 如果本次有第三个参数，证明是对评论进行回复
        obj.art_id = art_id
    }
    return request({
        url: '/v1_0/comments',
        method: 'POST',
        data: obj // 形参art_id可选参数，如果逻辑页面是对文章评论，则不需要传递art_id
    })
}